var  html_1='<li >'+
'<img class="li_img1Max" src="${user_img}" alt="">'+
'<div class="li_divMax">'+
    '<span class="li_spanMax">${user_id}</span>'+
    '<img class="li_img2" src="img/icon_skip.png" alt="">'+
'</div>'+
'</li>';

$(function ($) {
    var our_id = getUrlParam();
    var other_id;
    // var ip = "localhost";
    // var port = 8080;
    // var socket;
    // socket = new WebSocket("ws:" + ip + ":" + port);
    // socket.onmessage = function (e) {
    //     var data = e.data;
    //     console.log(data);
    //     var dataObj = eval("(" + data + ")");//转换为json对象
    //     get(dataObj);
    // }
    // function get(data) {
    //     var user = data.data;
    //     curUser = user;
    // }
    ajax_1();
    $('.li_spanMax').click(function () {
        other_id = $(this).text();
        console.log(our_id.id);
        console.log(other_id);
        window.location.href = 'chat.html?from=' + our_id.id + "&to=" + other_id;
    })
   function ajax_1(){
    var obj =new Object();
    obj.userid=our_id.id;
    console.log('1');
        $.ajax({
         "type": "POST",
         "url":  "/api/user/getOnline",
        //  .html   localhost:8888    /api/user/getOnline
         "data":obj , 
         "dataType": "json",
         "success":function(result){ 
             console.log(result);
             // var outHtml='';
             // for(var i=0;i<result.length;i++) {
             //     outHtml += html_1.replace('${user_id}', result[i].username);
             // }
             // $('.cont_ulMax').append(outHtml);
         },
         "error": function() {
           console.log('cuowu');
           
        }
        })
    }
    function getUrlParam() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
   
});